package com.coderman.basketball.statistics.service.eventhandler;

import com.coderman.basketball.statistics.context.CalculateContextBO;
import com.coderman.basketball.statistics.dto.GameEventDTO;
import com.coderman.basketball.statistics.dto.enums.PlayerStatisticsEnum;
import com.coderman.basketball.statistics.service.CalculateService;
import com.coderman.basketball.statistics.service.EventHandler;
import com.coderman.basketball.statistics.service.EventTag;

import javax.annotation.Resource;

/**
 * Description:
 * date: 2021/5/27
 *
 * @author shenshuai
 * @version 1.0.0
 * @since JDK 1.8
 */
@EventTag(eventType = "three_point")
public class ThreePointEventHandler implements EventHandler {
    @Resource(name = "scoreCalculateServiceImpl")
    private CalculateService scoreCalculateServiceImpl;

    @Resource(name = "shootingCalculateServiceImpl")
    private CalculateService shootingCalculateServiceImpl;

    @Override
    public boolean execute(GameEventDTO gameEventDTO) {
        CalculateContextBO calculateContextBO = new CalculateContextBO();
        calculateContextBO.setGameId(gameEventDTO.getGameId());
        calculateContextBO.setCount(1);
        calculateContextBO.setPlayerId(gameEventDTO.getPlayerId());
        //默认是true
        calculateContextBO.setIncr(true);
        calculateContextBO.setActionKey(PlayerStatisticsEnum.THREE_POINT_COUNT.getCode());
        shootingCalculateServiceImpl.calculate(calculateContextBO);

        if(gameEventDTO.isSuccess()){

            //分数+3
            CalculateContextBO scoreContextBO = new CalculateContextBO();
            calculateContextBO.setGameId(gameEventDTO.getGameId());
            calculateContextBO.setCount(3);
            calculateContextBO.setPlayerId(gameEventDTO.getPlayerId());
            //默认是true
            calculateContextBO.setIncr(true);
            calculateContextBO.setActionKey(PlayerStatisticsEnum.SCORE.getCode());
            scoreCalculateServiceImpl.calculate(scoreContextBO);

            //三分命中数+1
            CalculateContextBO threePointContextBO = new CalculateContextBO();
            calculateContextBO.setGameId(gameEventDTO.getGameId());
            calculateContextBO.setCount(1);
            calculateContextBO.setPlayerId(gameEventDTO.getPlayerId());
            //默认是true
            calculateContextBO.setIncr(true);
            calculateContextBO.setActionKey(PlayerStatisticsEnum.THREE_POINT_SUCCESS.getCode());
            shootingCalculateServiceImpl.calculate(threePointContextBO);
        }
        return true;
    }
}
